// components/Popup/bills/bills.js
import { toast } from '../../../utils/Tools'
import {
  showRemarks,
  showRemarksEdit
} from "../.././../network/client"
Component({
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  /**
   * 组件的属性列表
   */
  properties: {
    // 调用页传来的参数
    PageInfo: {
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    isShow: false,
    // 查看单据文字信息
    showRemarksInfo: '',
    // 查看单据图片路径
    showRemarksImg: '',

    // 总
    showRemarks: null,
    // 厂单号
    manufacturer: '',
    // 送货单号
    delivery: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 预览图片
    previewImg(e) {
      const { img } = e.currentTarget.dataset
      const urls = []
      urls.push(img)
      wx.previewImage({
        urls,
      })
    },
    vMode(e) {
      const { type } = e.currentTarget.dataset
      this.setData({
        [`showRemarks.${type}`]: e.detail.value
        // manufacturer:e.detail.value
      })

    },
    // 隐藏
    hideBills() {
      this.setData({
        isShow: !this.data.isShow
      })
    },
    // 显示
    showBills() {
      this._showRemarks()

      this.setData({
        isShow: !this.data.isShow
      })

    },
    // 提交
    async _billsSubmit() {

      const data = {
        order_id: this.data.PageInfo,
        supplement_factory_id: this.data.showRemarks.factoryId,
        order_code: this.data.showRemarks.orderCode

      }
      const res = await showRemarksEdit(data)
      if (res.code === 200) {
        toast('提交成功', 'success')
        wx.navigateBack({ delta: 1 })
      } else {
        toast(res.message)
      }
      // 关闭对话框
      this.hideBills()
      // 通知调用页
      this.triggerEvent("billsSubmit")
    },
    // _查看单据信息
    async _showRemarks() {
      let data = {
        order_id: this.data.PageInfo
      }
      const res = await showRemarks(data)
      // 图片路径数据处理
      let remarks = res.data.remarks_pic
      let remarksKey = Object.keys(remarks)[0]
      let remarks_pic = remarks[remarksKey];
      if (res.code == 200) {
        let showRemarksInfo = res.data.base_table
        this.setData({
          ["showRemarks.factoryId"]: showRemarksInfo.supplement_factory_id,
          ["showRemarks.orderCode"]: showRemarksInfo.order_code,
          // manufacturer:showRemarksInfo.supplement_factory_id,
          // delivery:showRemarksInfo.order_code,
          showRemarksImg: "http://master.gddzxcx.com" + remarks_pic
        })
      }


    },
  },


})